import re


def parse_usv_file(filepath):
    usvs = []
    with open(filepath, 'r') as f:
        for line in f:
            match = re.match(r'USV_ID:\s*(\d+),\s*Position:\s*\((\d+),\s*(\d+)\),\s*MaxSpeed:\s*([\d.]+),\s*Capacity:\s*(\d+)', line)
            if match:
                usvs.append({
                    'id': int(match.group(1)),
                    'pos': (int(match.group(2)), int(match.group(3))),
                    'speed': float(match.group(4)),
                    'max_load': int(match.group(5))
                })
    return usvs


def parse_port_file(filepath):
    ports = {}
    with open(filepath, 'r') as f:
        for line in f:
            match = re.match(r'Port\s+(\d+):\s*\((\d+),\s*(\d+)\)', line)
            if match:
                ports[int(match.group(1))] = (int(match.group(2)), int(match.group(3)))
    return ports


def parse_task_file(filepath):
    tasks = []
    with open(filepath, 'r') as f:
        for line in f:
            match = re.match(r'Task_ID:\s*(\d+),\s*StartPort:\s*\((\d+),\s*(\d+)\),\s*EndPort:\s*\((\d+),\s*(\d+)\),\s*Payload:\s*(\d+)', line)
            if match:
                tasks.append({
                    'id': int(match.group(1)),
                    'start_port': (int(match.group(2)), int(match.group(3))),
                    'end_port': (int(match.group(4)), int(match.group(5))),
                    'load': int(match.group(6))
                })
    return tasks
